package ysq.xyg.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import ysq.weixin.client.WxApiClient;
import ysq.weixin.client.WxMemoryCacheClient;
import ysq.weixin.model.info.JSTicketShareResponse;
import ysq.weixin.util.weatherApi;
import ysq.xyg.model.*;
import ysq.xyg.model.info.ReturnInfo;
import ysq.xyg.model.info.WxAccountInfo;
import ysq.xyg.service.*;
import ysq.xyg.util.BaseConstant;
import ysq.xyg.util.BaseUtil;
import ysq.xyg.util.DateUtil;
import ysq.xyg.util.ProProperties;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/6/23 0023.
 */
@Controller
@RequestMapping("/pc")
public class PcController extends BaseController {
    private static final Logger LOGGER= LoggerFactory.getLogger(PcController.class);
    @Resource
    private MemberService memberService;
    @Resource
    private ProductService productService;
    @Resource
    private ProductTypeService productTypeService;
    @Resource
    private RelayService relayService;
    @Resource
    private RelaySetService relaySetService;
    @Resource
    private DeviceService deviceService;


    private ModelAndView checkModelAndView;



    /**
     * 首页
     * */
    @RequestMapping("/index/{openid}")
    public ModelAndView index(HttpServletResponse response, HttpServletRequest request,@PathVariable String openid,String wxId) throws IOException {
      //  if(!check(openid, BaseConstant.WX_STATE_ONE)){
     //       return checkModelAndView;
      //  }
        Member member = memberService.selectByPrimaryKey(openid);
        List<Product> deviceList=productService.listLeft(new Product(BaseConstant.PRODUCT_TYPE_JCY,openid));
        if(deviceList!=null && deviceList.size()>0){
            for (int i=0;i<deviceList.size();i++){
                Product product=deviceList.get(i);
                Product d=productService.selectData(product);
                d=setTip(d);
                d.setDeviceType("2");
                if(d!=null&&d.getTime()!=null){
                    Date deviceDate= DateUtil.getSecondOneDate(d.getTime(),60*10);
                   if(deviceDate.getTime()>new Date().getTime()){
                    d.setDeviceType("1");
                   }
                }
                product.setNewProduct(d);
            }
        }
        /*
        List<Product> relayList=productService.listLeftK(new Product(BaseConstant.PRODUCT_TYPE_KZQ,openid));
        if(relayList!=null && relayList.size()>0){
            for (int i=0;i<relayList.size();i++){
                Product product=relayList.get(i);
                product.setDeviceType("2");
                if(product!=null&&product.getDeviceDate()!=null){
                    Date realyDate=DateUtil.getSecondOneDate(product.getDeviceDate(),60*10);
                    if(realyDate.getTime()>new Date().getTime()){
                        product.setDeviceType("1");
                    }
                }
            }
        }*/

        ModelAndView modelAndView=new ModelAndView("/pc/deviceList");
        modelAndView.addObject("openid",openid);
        modelAndView.addObject("deviceList",deviceList);
      //  modelAndView.addObject("relayList",relayList);
        modelAndView.addObject("jSTicketShareResponse",Share(request,wxId));
        modelAndView.addObject("member",member);
        return modelAndView;
    }

    @RequestMapping("/index1/{openid}")
    public ModelAndView index1(HttpServletResponse response, HttpServletRequest request,@PathVariable String openid,String wxId) throws IOException {
        //  if(!check(openid, BaseConstant.WX_STATE_ONE)){
        //       return checkModelAndView;
        //  }
        Member member = memberService.selectByPrimaryKey(openid);
        List<Product> deviceList=productService.listLeft(new Product(BaseConstant.PRODUCT_TYPE_JCY,openid));
        if(deviceList!=null && deviceList.size()>0){
            for (int i=0;i<deviceList.size();i++){
                Product product=deviceList.get(i);
                Product d=productService.selectData(product);
                d=setTip(d);
                d.setDeviceType("2");
                if(d!=null&&d.getTime()!=null){
                    Date deviceDate= DateUtil.getSecondOneDate(d.getTime(),60*10);
                    if(deviceDate.getTime()>new Date().getTime()){
                        d.setDeviceType("1");
                    }
                }
                product.setNewProduct(d);
            }
        }
        /*
        List<Product> relayList=productService.listLeftK(new Product(BaseConstant.PRODUCT_TYPE_KZQ,openid));
        if(relayList!=null && relayList.size()>0){
            for (int i=0;i<relayList.size();i++){
                Product product=relayList.get(i);
                product.setDeviceType("2");
                if(product!=null&&product.getDeviceDate()!=null){
                    Date realyDate=DateUtil.getSecondOneDate(product.getDeviceDate(),60*10);
                    if(realyDate.getTime()>new Date().getTime()){
                        product.setDeviceType("1");
                    }
                }
            }
        }*/

        ModelAndView modelAndView=new ModelAndView("/pc/deviceList1");
        modelAndView.addObject("openid",openid);
        modelAndView.addObject("deviceList",deviceList);
        //  modelAndView.addObject("relayList",relayList);
        modelAndView.addObject("jSTicketShareResponse",Share(request,wxId));
        modelAndView.addObject("member",member);
        return modelAndView;
    }

    @RequestMapping("/index2/{openid}")
    public ModelAndView index2(HttpServletResponse response, HttpServletRequest request,@PathVariable String openid,String wxId) throws IOException {
        //  if(!check(openid, BaseConstant.WX_STATE_ONE)){
        //       return checkModelAndView;
        //  }
        Member member = memberService.selectByPrimaryKey(openid);
        List<Product> deviceList=productService.listLeft(new Product(BaseConstant.PRODUCT_TYPE_JCY,openid));
        if(deviceList!=null && deviceList.size()>0){
            for (int i=0;i<deviceList.size();i++){
                Product product=deviceList.get(i);
                Product d=productService.selectData(product);
                d=setTip(d);
                d.setDeviceType("2");
                if(d!=null&&d.getTime()!=null){
                    Date deviceDate= DateUtil.getSecondOneDate(d.getTime(),60*10);
                    if(deviceDate.getTime()>new Date().getTime()){
                        d.setDeviceType("1");
                    }
                }
                product.setNewProduct(d);
            }
        }
        /*
        List<Product> relayList=productService.listLeftK(new Product(BaseConstant.PRODUCT_TYPE_KZQ,openid));
        if(relayList!=null && relayList.size()>0){
            for (int i=0;i<relayList.size();i++){
                Product product=relayList.get(i);
                product.setDeviceType("2");
                if(product!=null&&product.getDeviceDate()!=null){
                    Date realyDate=DateUtil.getSecondOneDate(product.getDeviceDate(),60*10);
                    if(realyDate.getTime()>new Date().getTime()){
                        product.setDeviceType("1");
                    }
                }
            }
        }*/

        ModelAndView modelAndView=new ModelAndView("/pc/deviceList2");
        modelAndView.addObject("openid",openid);
        modelAndView.addObject("deviceList",deviceList);
        //  modelAndView.addObject("relayList",relayList);
        modelAndView.addObject("jSTicketShareResponse",Share(request,wxId));
        modelAndView.addObject("member",member);
        return modelAndView;
    }
    @RequestMapping("/index3/{openid}")
    public ModelAndView index3(HttpServletResponse response, HttpServletRequest request,@PathVariable String openid,String wxId) throws IOException {
        //  if(!check(openid, BaseConstant.WX_STATE_ONE)){
        //       return checkModelAndView;
        //  }
        Member member = memberService.selectByPrimaryKey(openid);
        List<Product> deviceList=productService.listLeft(new Product(BaseConstant.PRODUCT_TYPE_JCY,openid));
        if(deviceList!=null && deviceList.size()>0){
            for (int i=0;i<deviceList.size();i++){
                Product product=deviceList.get(i);
                Product d=productService.selectData(product);
                d=setTip(d);
                d.setDeviceType("2");
                if(d!=null&&d.getTime()!=null){
                    Date deviceDate= DateUtil.getSecondOneDate(d.getTime(),60*10);
                    if(deviceDate.getTime()>new Date().getTime()){
                        d.setDeviceType("1");
                    }
                }
                product.setNewProduct(d);
            }
        }
        /*
        List<Product> relayList=productService.listLeftK(new Product(BaseConstant.PRODUCT_TYPE_KZQ,openid));
        if(relayList!=null && relayList.size()>0){
            for (int i=0;i<relayList.size();i++){
                Product product=relayList.get(i);
                product.setDeviceType("2");
                if(product!=null&&product.getDeviceDate()!=null){
                    Date realyDate=DateUtil.getSecondOneDate(product.getDeviceDate(),60*10);
                    if(realyDate.getTime()>new Date().getTime()){
                        product.setDeviceType("1");
                    }
                }
            }
        }*/

        ModelAndView modelAndView=new ModelAndView("/pc/deviceList3");
        modelAndView.addObject("openid",openid);
        modelAndView.addObject("deviceList",deviceList);
        //  modelAndView.addObject("relayList",relayList);
        modelAndView.addObject("jSTicketShareResponse",Share(request,wxId));
        modelAndView.addObject("member",member);
        return modelAndView;
    }


    @RequestMapping("/index4/{openid}")
    public ModelAndView index4(HttpServletResponse response, HttpServletRequest request,@PathVariable String openid,String wxId) throws IOException {
        //  if(!check(openid, BaseConstant.WX_STATE_ONE)){
        //       return checkModelAndView;
        //  }
        Member member = memberService.selectByPrimaryKey(openid);
        List<Product> deviceList=productService.listLeft(new Product(BaseConstant.PRODUCT_TYPE_JCY,openid));
        if(deviceList!=null && deviceList.size()>0){
            for (int i=0;i<deviceList.size();i++){
                Product product=deviceList.get(i);
                Product d=productService.selectData(product);
                d=setTip(d);
                d.setDeviceType("2");
                if(d!=null&&d.getTime()!=null){
                    Date deviceDate= DateUtil.getSecondOneDate(d.getTime(),60*10);
                    if(deviceDate.getTime()>new Date().getTime()){
                        d.setDeviceType("1");
                    }
                }
                product.setNewProduct(d);
            }
        }
        /*
        List<Product> relayList=productService.listLeftK(new Product(BaseConstant.PRODUCT_TYPE_KZQ,openid));
        if(relayList!=null && relayList.size()>0){
            for (int i=0;i<relayList.size();i++){
                Product product=relayList.get(i);
                product.setDeviceType("2");
                if(product!=null&&product.getDeviceDate()!=null){
                    Date realyDate=DateUtil.getSecondOneDate(product.getDeviceDate(),60*10);
                    if(realyDate.getTime()>new Date().getTime()){
                        product.setDeviceType("1");
                    }
                }
            }
        }*/

        ModelAndView modelAndView=new ModelAndView("/pc/deviceList4");
        modelAndView.addObject("openid",openid);
        modelAndView.addObject("deviceList",deviceList);
        //  modelAndView.addObject("relayList",relayList);
        modelAndView.addObject("jSTicketShareResponse",Share(request,wxId));
        modelAndView.addObject("member",member);
        return modelAndView;
    }

    @RequestMapping("/index5/{openid}")
    public ModelAndView index5(HttpServletResponse response, HttpServletRequest request,@PathVariable String openid,String wxId) throws IOException {
        //  if(!check(openid, BaseConstant.WX_STATE_ONE)){
        //       return checkModelAndView;
        //  }
        Member member = memberService.selectByPrimaryKey(openid);
        List<Product> deviceList=productService.listLeft(new Product(BaseConstant.PRODUCT_TYPE_JCY,openid));
        if(deviceList!=null && deviceList.size()>0){
            for (int i=0;i<deviceList.size();i++){
                Product product=deviceList.get(i);
                Product d=productService.selectData(product);
                d=setTip(d);
                d.setDeviceType("2");
                if(d!=null&&d.getTime()!=null){
                    Date deviceDate= DateUtil.getSecondOneDate(d.getTime(),60*10);
                    if(deviceDate.getTime()>new Date().getTime()){
                        d.setDeviceType("1");
                    }
                }
                product.setNewProduct(d);
            }
        }
        /*
        List<Product> relayList=productService.listLeftK(new Product(BaseConstant.PRODUCT_TYPE_KZQ,openid));
        if(relayList!=null && relayList.size()>0){
            for (int i=0;i<relayList.size();i++){
                Product product=relayList.get(i);
                product.setDeviceType("2");
                if(product!=null&&product.getDeviceDate()!=null){
                    Date realyDate=DateUtil.getSecondOneDate(product.getDeviceDate(),60*10);
                    if(realyDate.getTime()>new Date().getTime()){
                        product.setDeviceType("1");
                    }
                }
            }
        }*/

        ModelAndView modelAndView=new ModelAndView("/pc/deviceList5");
        modelAndView.addObject("openid",openid);
        modelAndView.addObject("deviceList",deviceList);
        //  modelAndView.addObject("relayList",relayList);
        modelAndView.addObject("jSTicketShareResponse",Share(request,wxId));
        modelAndView.addObject("member",member);
        return modelAndView;
    }


    @RequestMapping("/envoair1/{openid}")
    public ModelAndView envoair1(HttpServletResponse response, HttpServletRequest request,@PathVariable String openid,String wxId) throws IOException {
        //  if(!check(openid, BaseConstant.WX_STATE_ONE)){
        //       return checkModelAndView;
        //  }
        Member member = memberService.selectByPrimaryKey(openid);
        List<Product> deviceList=productService.listLeft(new Product(BaseConstant.PRODUCT_TYPE_JCY,openid));
        if(deviceList!=null && deviceList.size()>0){
            for (int i=0;i<deviceList.size();i++){
                Product product=deviceList.get(i);
                Product d=productService.selectData(product);
                d=setTip(d);
                d.setDeviceType("2");
                if(d!=null&&d.getTime()!=null){
                    Date deviceDate= DateUtil.getSecondOneDate(d.getTime(),60*10);
                    if(deviceDate.getTime()>new Date().getTime()){
                        d.setDeviceType("1");
                    }
                }
                product.setNewProduct(d);
            }
        }
        /*
        List<Product> relayList=productService.listLeftK(new Product(BaseConstant.PRODUCT_TYPE_KZQ,openid));
        if(relayList!=null && relayList.size()>0){
            for (int i=0;i<relayList.size();i++){
                Product product=relayList.get(i);
                product.setDeviceType("2");
                if(product!=null&&product.getDeviceDate()!=null){
                    Date realyDate=DateUtil.getSecondOneDate(product.getDeviceDate(),60*10);
                    if(realyDate.getTime()>new Date().getTime()){
                        product.setDeviceType("1");
                    }
                }
            }
        }*/

        ModelAndView modelAndView=new ModelAndView("/pc/envoair1");
        modelAndView.addObject("openid",openid);
        modelAndView.addObject("deviceList",deviceList);
        //  modelAndView.addObject("relayList",relayList);
        modelAndView.addObject("jSTicketShareResponse",Share(request,wxId));
        modelAndView.addObject("member",member);
        return modelAndView;
    }

    @RequestMapping("/envoair2/{openid}")
    public ModelAndView envoair2(HttpServletResponse response, HttpServletRequest request,@PathVariable String openid,String wxId) throws IOException {
        //  if(!check(openid, BaseConstant.WX_STATE_ONE)){
        //       return checkModelAndView;
        //  }
        Member member = memberService.selectByPrimaryKey(openid);
        List<Product> deviceList=productService.listLeft(new Product(BaseConstant.PRODUCT_TYPE_JCY,openid));
        if(deviceList!=null && deviceList.size()>0){
            for (int i=0;i<deviceList.size();i++){
                Product product=deviceList.get(i);
                Product d=productService.selectData(product);
                d=setTip(d);
                d.setDeviceType("2");
                if(d!=null&&d.getTime()!=null){
                    Date deviceDate= DateUtil.getSecondOneDate(d.getTime(),60*10);
                    if(deviceDate.getTime()>new Date().getTime()){
                        d.setDeviceType("1");
                    }
                }
                product.setNewProduct(d);
            }
        }
        /*
        List<Product> relayList=productService.listLeftK(new Product(BaseConstant.PRODUCT_TYPE_KZQ,openid));
        if(relayList!=null && relayList.size()>0){
            for (int i=0;i<relayList.size();i++){
                Product product=relayList.get(i);
                product.setDeviceType("2");
                if(product!=null&&product.getDeviceDate()!=null){
                    Date realyDate=DateUtil.getSecondOneDate(product.getDeviceDate(),60*10);
                    if(realyDate.getTime()>new Date().getTime()){
                        product.setDeviceType("1");
                    }
                }
            }
        }*/

        ModelAndView modelAndView=new ModelAndView("/pc/envoair2");
        modelAndView.addObject("openid",openid);
        modelAndView.addObject("deviceList",deviceList);
        //  modelAndView.addObject("relayList",relayList);
        modelAndView.addObject("jSTicketShareResponse",Share(request,wxId));
        modelAndView.addObject("member",member);
        return modelAndView;
    }


    @RequestMapping("/envoair3/{openid}")
    public ModelAndView envoair3(HttpServletResponse response, HttpServletRequest request,@PathVariable String openid,String wxId) throws IOException {
        //  if(!check(openid, BaseConstant.WX_STATE_ONE)){
        //       return checkModelAndView;
        //  }
        Member member = memberService.selectByPrimaryKey(openid);
        List<Product> deviceList=productService.listLeft(new Product(BaseConstant.PRODUCT_TYPE_JCY,openid));
        if(deviceList!=null && deviceList.size()>0){
            for (int i=0;i<deviceList.size();i++){
                Product product=deviceList.get(i);
                Product d=productService.selectData(product);
                d=setTip(d);
                d.setDeviceType("2");
                if(d!=null&&d.getTime()!=null){
                    Date deviceDate= DateUtil.getSecondOneDate(d.getTime(),60*10);
                    if(deviceDate.getTime()>new Date().getTime()){
                        d.setDeviceType("1");
                    }
                }
                product.setNewProduct(d);
            }
        }
        /*
        List<Product> relayList=productService.listLeftK(new Product(BaseConstant.PRODUCT_TYPE_KZQ,openid));
        if(relayList!=null && relayList.size()>0){
            for (int i=0;i<relayList.size();i++){
                Product product=relayList.get(i);
                product.setDeviceType("2");
                if(product!=null&&product.getDeviceDate()!=null){
                    Date realyDate=DateUtil.getSecondOneDate(product.getDeviceDate(),60*10);
                    if(realyDate.getTime()>new Date().getTime()){
                        product.setDeviceType("1");
                    }
                }
            }
        }*/

        ModelAndView modelAndView=new ModelAndView("/pc/envoair3");
        modelAndView.addObject("openid",openid);
        modelAndView.addObject("deviceList",deviceList);
        //  modelAndView.addObject("relayList",relayList);
        modelAndView.addObject("jSTicketShareResponse",Share(request,wxId));
        modelAndView.addObject("member",member);
        return modelAndView;
    }


    @RequestMapping("/envoair4/{openid}")
    public ModelAndView envoair4(HttpServletResponse response, HttpServletRequest request,@PathVariable String openid,String wxId) throws IOException {
        //  if(!check(openid, BaseConstant.WX_STATE_ONE)){
        //       return checkModelAndView;
        //  }
        Member member = memberService.selectByPrimaryKey(openid);
        List<Product> deviceList=productService.listLeft(new Product(BaseConstant.PRODUCT_TYPE_JCY,openid));
        if(deviceList!=null && deviceList.size()>0){
            for (int i=0;i<deviceList.size();i++){
                Product product=deviceList.get(i);
                Product d=productService.selectData(product);
                d=setTip(d);
                d.setDeviceType("2");
                if(d!=null&&d.getTime()!=null){
                    Date deviceDate= DateUtil.getSecondOneDate(d.getTime(),60*10);
                    if(deviceDate.getTime()>new Date().getTime()){
                        d.setDeviceType("1");
                    }
                }
                product.setNewProduct(d);
            }
        }
        /*
        List<Product> relayList=productService.listLeftK(new Product(BaseConstant.PRODUCT_TYPE_KZQ,openid));
        if(relayList!=null && relayList.size()>0){
            for (int i=0;i<relayList.size();i++){
                Product product=relayList.get(i);
                product.setDeviceType("2");
                if(product!=null&&product.getDeviceDate()!=null){
                    Date realyDate=DateUtil.getSecondOneDate(product.getDeviceDate(),60*10);
                    if(realyDate.getTime()>new Date().getTime()){
                        product.setDeviceType("1");
                    }
                }
            }
        }*/

        ModelAndView modelAndView=new ModelAndView("/pc/envoair4");
        modelAndView.addObject("openid",openid);
        modelAndView.addObject("deviceList",deviceList);
        //  modelAndView.addObject("relayList",relayList);
        modelAndView.addObject("jSTicketShareResponse",Share(request,wxId));
        modelAndView.addObject("member",member);
        return modelAndView;
    }

    @RequestMapping("/envoair5/{openid}")
    public ModelAndView envoair5(HttpServletResponse response, HttpServletRequest request,@PathVariable String openid,String wxId) throws IOException {
        //  if(!check(openid, BaseConstant.WX_STATE_ONE)){
        //       return checkModelAndView;
        //  }
        Member member = memberService.selectByPrimaryKey(openid);
        List<Product> deviceList=productService.listLeft(new Product(BaseConstant.PRODUCT_TYPE_JCY,openid));
        if(deviceList!=null && deviceList.size()>0){
            for (int i=0;i<deviceList.size();i++){
                Product product=deviceList.get(i);
                Product d=productService.selectData(product);
                d=setTip(d);
                d.setDeviceType("2");
                if(d!=null&&d.getTime()!=null){
                    Date deviceDate= DateUtil.getSecondOneDate(d.getTime(),60*10);
                    if(deviceDate.getTime()>new Date().getTime()){
                        d.setDeviceType("1");
                    }
                }
                product.setNewProduct(d);
            }
        }
        /*
        List<Product> relayList=productService.listLeftK(new Product(BaseConstant.PRODUCT_TYPE_KZQ,openid));
        if(relayList!=null && relayList.size()>0){
            for (int i=0;i<relayList.size();i++){
                Product product=relayList.get(i);
                product.setDeviceType("2");
                if(product!=null&&product.getDeviceDate()!=null){
                    Date realyDate=DateUtil.getSecondOneDate(product.getDeviceDate(),60*10);
                    if(realyDate.getTime()>new Date().getTime()){
                        product.setDeviceType("1");
                    }
                }
            }
        }*/

        ModelAndView modelAndView=new ModelAndView("/pc/envoair5");
        modelAndView.addObject("openid",openid);
        modelAndView.addObject("deviceList",deviceList);
        //  modelAndView.addObject("relayList",relayList);
        modelAndView.addObject("jSTicketShareResponse",Share(request,wxId));
        modelAndView.addObject("member",member);
        return modelAndView;
    }

    @RequestMapping("/envoair6/{openid}")
    public ModelAndView envoair6(HttpServletResponse response, HttpServletRequest request,@PathVariable String openid,String wxId) throws IOException {
        //  if(!check(openid, BaseConstant.WX_STATE_ONE)){
        //       return checkModelAndView;
        //  }
        Member member = memberService.selectByPrimaryKey(openid);
        List<Product> deviceList=productService.listLeft(new Product(BaseConstant.PRODUCT_TYPE_JCY,openid));
        if(deviceList!=null && deviceList.size()>0){
            for (int i=0;i<deviceList.size();i++){
                Product product=deviceList.get(i);
                Product d=productService.selectData(product);
                d=setTip(d);
                d.setDeviceType("2");
                if(d!=null&&d.getTime()!=null){
                    Date deviceDate= DateUtil.getSecondOneDate(d.getTime(),60*10);
                    if(deviceDate.getTime()>new Date().getTime()){
                        d.setDeviceType("1");
                    }
                }
                product.setNewProduct(d);
            }
        }
        /*
        List<Product> relayList=productService.listLeftK(new Product(BaseConstant.PRODUCT_TYPE_KZQ,openid));
        if(relayList!=null && relayList.size()>0){
            for (int i=0;i<relayList.size();i++){
                Product product=relayList.get(i);
                product.setDeviceType("2");
                if(product!=null&&product.getDeviceDate()!=null){
                    Date realyDate=DateUtil.getSecondOneDate(product.getDeviceDate(),60*10);
                    if(realyDate.getTime()>new Date().getTime()){
                        product.setDeviceType("1");
                    }
                }
            }
        }*/

        ModelAndView modelAndView=new ModelAndView("/pc/envoair6");
        modelAndView.addObject("openid",openid);
        modelAndView.addObject("deviceList",deviceList);
        //  modelAndView.addObject("relayList",relayList);
        modelAndView.addObject("jSTicketShareResponse",Share(request,wxId));
        modelAndView.addObject("member",member);
        return modelAndView;
    }


    @RequestMapping("/envoair7/{openid}")
    public ModelAndView envoair7(HttpServletResponse response, HttpServletRequest request,@PathVariable String openid,String wxId) throws IOException {
        //  if(!check(openid, BaseConstant.WX_STATE_ONE)){
        //       return checkModelAndView;
        //  }
        Member member = memberService.selectByPrimaryKey(openid);
        List<Product> deviceList=productService.listLeft(new Product(BaseConstant.PRODUCT_TYPE_JCY,openid));
        if(deviceList!=null && deviceList.size()>0){
            for (int i=0;i<deviceList.size();i++){
                Product product=deviceList.get(i);
                Product d=productService.selectData(product);
                d=setTip(d);
                d.setDeviceType("2");
                if(d!=null&&d.getTime()!=null){
                    Date deviceDate= DateUtil.getSecondOneDate(d.getTime(),60*10);
                    if(deviceDate.getTime()>new Date().getTime()){
                        d.setDeviceType("1");
                    }
                }
                product.setNewProduct(d);
            }
        }
        /*
        List<Product> relayList=productService.listLeftK(new Product(BaseConstant.PRODUCT_TYPE_KZQ,openid));
        if(relayList!=null && relayList.size()>0){
            for (int i=0;i<relayList.size();i++){
                Product product=relayList.get(i);
                product.setDeviceType("2");
                if(product!=null&&product.getDeviceDate()!=null){
                    Date realyDate=DateUtil.getSecondOneDate(product.getDeviceDate(),60*10);
                    if(realyDate.getTime()>new Date().getTime()){
                        product.setDeviceType("1");
                    }
                }
            }
        }*/

        ModelAndView modelAndView=new ModelAndView("/pc/envoair7");
        modelAndView.addObject("openid",openid);
        modelAndView.addObject("deviceList",deviceList);
        //  modelAndView.addObject("relayList",relayList);
        modelAndView.addObject("jSTicketShareResponse",Share(request,wxId));
        modelAndView.addObject("member",member);
        return modelAndView;
    }


    @RequestMapping("/envoair8/{openid}")
    public ModelAndView envoair8(HttpServletResponse response, HttpServletRequest request,@PathVariable String openid,String wxId) throws IOException {
        //  if(!check(openid, BaseConstant.WX_STATE_ONE)){
        //       return checkModelAndView;
        //  }
        Member member = memberService.selectByPrimaryKey(openid);
        List<Product> deviceList=productService.listLeft(new Product(BaseConstant.PRODUCT_TYPE_JCY,openid));
        if(deviceList!=null && deviceList.size()>0){
            for (int i=0;i<deviceList.size();i++){
                Product product=deviceList.get(i);
                Product d=productService.selectData(product);
                d=setTip(d);
                d.setDeviceType("2");
                if(d!=null&&d.getTime()!=null){
                    Date deviceDate= DateUtil.getSecondOneDate(d.getTime(),60*10);
                    if(deviceDate.getTime()>new Date().getTime()){
                        d.setDeviceType("1");
                    }
                }
                product.setNewProduct(d);
            }
        }
        /*
        List<Product> relayList=productService.listLeftK(new Product(BaseConstant.PRODUCT_TYPE_KZQ,openid));
        if(relayList!=null && relayList.size()>0){
            for (int i=0;i<relayList.size();i++){
                Product product=relayList.get(i);
                product.setDeviceType("2");
                if(product!=null&&product.getDeviceDate()!=null){
                    Date realyDate=DateUtil.getSecondOneDate(product.getDeviceDate(),60*10);
                    if(realyDate.getTime()>new Date().getTime()){
                        product.setDeviceType("1");
                    }
                }
            }
        }*/

        ModelAndView modelAndView=new ModelAndView("/pc/envoair8");
        modelAndView.addObject("openid",openid);
        modelAndView.addObject("deviceList",deviceList);
        //  modelAndView.addObject("relayList",relayList);
        modelAndView.addObject("jSTicketShareResponse",Share(request,wxId));
        modelAndView.addObject("member",member);
        return modelAndView;
    }




    @RequestMapping("/envoair9/{openid}")
    public ModelAndView envoair9(HttpServletResponse response, HttpServletRequest request,@PathVariable String openid,String wxId) throws IOException {
        //  if(!check(openid, BaseConstant.WX_STATE_ONE)){
        //       return checkModelAndView;
        //  }
        Member member = memberService.selectByPrimaryKey(openid);
        List<Product> deviceList=productService.listLeft(new Product(BaseConstant.PRODUCT_TYPE_JCY,openid));
        if(deviceList!=null && deviceList.size()>0){
            for (int i=0;i<deviceList.size();i++){
                Product product=deviceList.get(i);
                Product d=productService.selectData(product);
                d=setTip(d);
                d.setDeviceType("2");
                if(d!=null&&d.getTime()!=null){
                    Date deviceDate= DateUtil.getSecondOneDate(d.getTime(),60*10);
                    if(deviceDate.getTime()>new Date().getTime()){
                        d.setDeviceType("1");
                    }
                }
                product.setNewProduct(d);
            }
        }
        /*
        List<Product> relayList=productService.listLeftK(new Product(BaseConstant.PRODUCT_TYPE_KZQ,openid));
        if(relayList!=null && relayList.size()>0){
            for (int i=0;i<relayList.size();i++){
                Product product=relayList.get(i);
                product.setDeviceType("2");
                if(product!=null&&product.getDeviceDate()!=null){
                    Date realyDate=DateUtil.getSecondOneDate(product.getDeviceDate(),60*10);
                    if(realyDate.getTime()>new Date().getTime()){
                        product.setDeviceType("1");
                    }
                }
            }
        }*/

        ModelAndView modelAndView=new ModelAndView("/pc/envoair9");
        modelAndView.addObject("openid",openid);
        modelAndView.addObject("deviceList",deviceList);
        //  modelAndView.addObject("relayList",relayList);
        modelAndView.addObject("jSTicketShareResponse",Share(request,wxId));
        modelAndView.addObject("member",member);
        return modelAndView;
    }

    @RequestMapping("/envoair10/{openid}")
    public ModelAndView envoair10(HttpServletResponse response, HttpServletRequest request,@PathVariable String openid,String wxId) throws IOException {
        //  if(!check(openid, BaseConstant.WX_STATE_ONE)){
        //       return checkModelAndView;
        //  }
        Member member = memberService.selectByPrimaryKey(openid);
        List<Product> deviceList=productService.listLeft(new Product(BaseConstant.PRODUCT_TYPE_JCY,openid));
        if(deviceList!=null && deviceList.size()>0){
            for (int i=0;i<deviceList.size();i++){
                Product product=deviceList.get(i);
                Product d=productService.selectData(product);
                d=setTip(d);
                d.setDeviceType("2");
                if(d!=null&&d.getTime()!=null){
                    Date deviceDate= DateUtil.getSecondOneDate(d.getTime(),60*10);
                    if(deviceDate.getTime()>new Date().getTime()){
                        d.setDeviceType("1");
                    }
                }
                product.setNewProduct(d);
            }
        }
        /*
        List<Product> relayList=productService.listLeftK(new Product(BaseConstant.PRODUCT_TYPE_KZQ,openid));
        if(relayList!=null && relayList.size()>0){
            for (int i=0;i<relayList.size();i++){
                Product product=relayList.get(i);
                product.setDeviceType("2");
                if(product!=null&&product.getDeviceDate()!=null){
                    Date realyDate=DateUtil.getSecondOneDate(product.getDeviceDate(),60*10);
                    if(realyDate.getTime()>new Date().getTime()){
                        product.setDeviceType("1");
                    }
                }
            }
        }*/

        ModelAndView modelAndView=new ModelAndView("/pc/envoair10");
        modelAndView.addObject("openid",openid);
        modelAndView.addObject("deviceList",deviceList);
        //  modelAndView.addObject("relayList",relayList);
        modelAndView.addObject("jSTicketShareResponse",Share(request,wxId));
        modelAndView.addObject("member",member);
        return modelAndView;
    }


    @RequestMapping("/envoair11/{openid}")
    public ModelAndView envoair11(HttpServletResponse response, HttpServletRequest request,@PathVariable String openid,String wxId) throws IOException {
        //  if(!check(openid, BaseConstant.WX_STATE_ONE)){
        //       return checkModelAndView;
        //  }
        Member member = memberService.selectByPrimaryKey(openid);
        List<Product> deviceList=productService.listLeft(new Product(BaseConstant.PRODUCT_TYPE_JCY,openid));
        if(deviceList!=null && deviceList.size()>0){
            for (int i=0;i<deviceList.size();i++){
                Product product=deviceList.get(i);
                Product d=productService.selectData(product);
                d=setTip(d);
                d.setDeviceType("2");
                if(d!=null&&d.getTime()!=null){
                    Date deviceDate= DateUtil.getSecondOneDate(d.getTime(),60*10);
                    if(deviceDate.getTime()>new Date().getTime()){
                        d.setDeviceType("1");
                    }
                }
                product.setNewProduct(d);
            }
        }
        /*
        List<Product> relayList=productService.listLeftK(new Product(BaseConstant.PRODUCT_TYPE_KZQ,openid));
        if(relayList!=null && relayList.size()>0){
            for (int i=0;i<relayList.size();i++){
                Product product=relayList.get(i);
                product.setDeviceType("2");
                if(product!=null&&product.getDeviceDate()!=null){
                    Date realyDate=DateUtil.getSecondOneDate(product.getDeviceDate(),60*10);
                    if(realyDate.getTime()>new Date().getTime()){
                        product.setDeviceType("1");
                    }
                }
            }
        }*/

        ModelAndView modelAndView=new ModelAndView("/pc/envoair11");
        modelAndView.addObject("openid",openid);
        modelAndView.addObject("deviceList",deviceList);
        //  modelAndView.addObject("relayList",relayList);
        modelAndView.addObject("jSTicketShareResponse",Share(request,wxId));
        modelAndView.addObject("member",member);
        return modelAndView;
    }


    @RequestMapping("/envoair12/{openid}")
    public ModelAndView envoair12(HttpServletResponse response, HttpServletRequest request,@PathVariable String openid,String wxId) throws IOException {
        //  if(!check(openid, BaseConstant.WX_STATE_ONE)){
        //       return checkModelAndView;
        //  }
        Member member = memberService.selectByPrimaryKey(openid);
        List<Product> deviceList=productService.listLeft(new Product(BaseConstant.PRODUCT_TYPE_JCY,openid));
        if(deviceList!=null && deviceList.size()>0){
            for (int i=0;i<deviceList.size();i++){
                Product product=deviceList.get(i);
                Product d=productService.selectData(product);
                d=setTip(d);
                d.setDeviceType("2");
                if(d!=null&&d.getTime()!=null){
                    Date deviceDate= DateUtil.getSecondOneDate(d.getTime(),60*10);
                    if(deviceDate.getTime()>new Date().getTime()){
                        d.setDeviceType("1");
                    }
                }
                product.setNewProduct(d);
            }
        }
        /*
        List<Product> relayList=productService.listLeftK(new Product(BaseConstant.PRODUCT_TYPE_KZQ,openid));
        if(relayList!=null && relayList.size()>0){
            for (int i=0;i<relayList.size();i++){
                Product product=relayList.get(i);
                product.setDeviceType("2");
                if(product!=null&&product.getDeviceDate()!=null){
                    Date realyDate=DateUtil.getSecondOneDate(product.getDeviceDate(),60*10);
                    if(realyDate.getTime()>new Date().getTime()){
                        product.setDeviceType("1");
                    }
                }
            }
        }*/

        ModelAndView modelAndView=new ModelAndView("/pc/envoair12");
        modelAndView.addObject("openid",openid);
        modelAndView.addObject("deviceList",deviceList);
        //  modelAndView.addObject("relayList",relayList);
        modelAndView.addObject("jSTicketShareResponse",Share(request,wxId));
        modelAndView.addObject("member",member);
        return modelAndView;
    }



    /**
     * 添加页面跳转链接
     * */
    @RequestMapping("/add/{openid}")
    public ModelAndView add(HttpServletResponse response, HttpServletRequest request,@PathVariable String openid,String deviceId,String type,String wxId) throws IOException {
        if(!check(openid, BaseConstant.WX_STATE_ONE)){
            return checkModelAndView;
        }
        List<ProductType> productTypeList=productTypeService.selectAll();
        ModelAndView modelAndView=new ModelAndView("/pc/addProduct");
        modelAndView.addObject("openid",openid);
        modelAndView.addObject("deviceId",deviceId);
        modelAndView.addObject("type",type);
        modelAndView.addObject("productTypeList",productTypeList);
        modelAndView.addObject("jSTicketShareResponse",Share(request,wxId));
        return modelAndView;
    }
    /**
     * 添加页面跳转链接
     * */
    @RequestMapping("/add1/{openid}")
    public ModelAndView add1(HttpServletResponse response, HttpServletRequest request,@PathVariable String openid,String deviceId,String type,String wxId) throws IOException {
        if(!check(openid, BaseConstant.WX_STATE_ONE)){
            return checkModelAndView;
        }
        List<ProductType> productTypeList=productTypeService.selectAll();
        ModelAndView modelAndView=new ModelAndView("/pc/addProduct1");
        modelAndView.addObject("openid",openid);
        modelAndView.addObject("deviceId",deviceId);
        modelAndView.addObject("type",type);
        modelAndView.addObject("productTypeList",productTypeList);
        modelAndView.addObject("jSTicketShareResponse",Share(request,wxId));
        return modelAndView;
    }

    /**
     * 添加页面跳转链接
     * */
    @RequestMapping("/add4/{openid}")
    public ModelAndView add4(HttpServletResponse response, HttpServletRequest request,@PathVariable String openid,String deviceId,String type,String wxId) throws IOException {
        if(!check(openid, BaseConstant.WX_STATE_ONE)){
            return checkModelAndView;
        }
        List<ProductType> productTypeList=productTypeService.selectAll();
        ModelAndView modelAndView=new ModelAndView("/pc/addProduct4");
        modelAndView.addObject("openid",openid);
        modelAndView.addObject("deviceId",deviceId);
        modelAndView.addObject("type",type);
        modelAndView.addObject("productTypeList",productTypeList);
        modelAndView.addObject("jSTicketShareResponse",Share(request,wxId));
        return modelAndView;
    }

    /**
     * 添加页面跳转链接
     * */
    @RequestMapping("/add5/{openid}")
    public ModelAndView add5(HttpServletResponse response, HttpServletRequest request,@PathVariable String openid,String deviceId,String type,String wxId) throws IOException {
        if(!check(openid, BaseConstant.WX_STATE_ONE)){
            return checkModelAndView;
        }
        List<ProductType> productTypeList=productTypeService.selectAll();
        ModelAndView modelAndView=new ModelAndView("/pc/addProduct5");
        modelAndView.addObject("openid",openid);
        modelAndView.addObject("deviceId",deviceId);
        modelAndView.addObject("type",type);
        modelAndView.addObject("productTypeList",productTypeList);
        modelAndView.addObject("jSTicketShareResponse",Share(request,wxId));
        return modelAndView;
    }

    /**
     * 添加页面跳转链接
     * */
    @RequestMapping("/add6/{openid}")
    public ModelAndView add6(HttpServletResponse response, HttpServletRequest request,@PathVariable String openid,String deviceId,String type,String wxId) throws IOException {
        if(!check(openid, BaseConstant.WX_STATE_ONE)){
            return checkModelAndView;
        }
        List<ProductType> productTypeList=productTypeService.selectAll();
        ModelAndView modelAndView=new ModelAndView("/pc/addProduct6");
        modelAndView.addObject("openid",openid);
        modelAndView.addObject("deviceId",deviceId);
        modelAndView.addObject("type",type);
        modelAndView.addObject("productTypeList",productTypeList);
        modelAndView.addObject("jSTicketShareResponse",Share(request,wxId));
        return modelAndView;
    }




    /**
     * 设备添加
     * */
    @RequestMapping(value = "/addProduct/{openid}")
    public @ResponseBody
    JSONObject EvaluateList(@PathVariable String openid, Product product) throws MalformedURLException, UnsupportedEncodingException {
        ReturnInfo returnInfo=new ReturnInfo();
        JSONObject jsonObject=new JSONObject();
        if(product==null||StringUtil.isEmpty(product.getProductTypeId())||StringUtil.isEmpty(product.getDeviceId())||StringUtil.isEmpty(product.getName())){
            returnInfo=new ReturnInfo(BaseConstant.FAIL,"参数输入错误！");
            jsonObject.put("returnInfo",returnInfo);
            return jsonObject;
        }

        /*List<Product> productList=productService.list(new Product(product.getDeviceId()));
        if(productList!=null&&productList.size()>0){
            returnInfo=new ReturnInfo(BaseConstant.FAIL,"设备ID为["+product.getDeviceId()+"]已经被绑定！");
            jsonObject.put("returnInfo",returnInfo);
            return jsonObject;
        }*/
        if(BaseConstant.PRODUCT_TYPE_KZQ.equals(product.getProductTypeId())){
            List<Relay> relayList=relayService.list(new Relay(product.getDeviceId()));
            if(relayList==null||relayList.size()<=0){
                returnInfo=new ReturnInfo(BaseConstant.FAIL,"设备ID和设备类型不匹配！");
                jsonObject.put("returnInfo",returnInfo);
                return jsonObject;
            }
        }else{
            List<Device> deviceList=deviceService.list(new Device(product.getDeviceId()));
            if(deviceList==null||deviceList.size()<=0){
                returnInfo=new ReturnInfo(BaseConstant.FAIL,"设备ID和设备类型不匹配！");
                jsonObject.put("returnInfo",returnInfo);
                return jsonObject;
            }
        }
        product.setId(BaseUtil.uId());
        product.setCreateTime(new Date());
        product.setOpenid(openid);
        int id=productService.insert(product);
        if(id<=0){
            returnInfo=new ReturnInfo(BaseConstant.FAIL,"设备添加失败！");
        }
        jsonObject.put("returnInfo",returnInfo);
        return jsonObject;
    }



    /**
     * 设备删除修改
     * */
    @RequestMapping(value = "/deleteDevice")
    public @ResponseBody
    JSONObject deleteDevice(String productId) throws MalformedURLException, UnsupportedEncodingException {
        ReturnInfo returnInfo=new ReturnInfo();
        JSONObject jsonObject=new JSONObject();
        if(productId==null){
            returnInfo=new ReturnInfo(BaseConstant.FAIL,"参数输入错误！");
            jsonObject.put("returnInfo",returnInfo);
            return jsonObject;
        }
        int id=productService.deleteByPrimaryKey(productId);
        if(id<=0){
            returnInfo=new ReturnInfo(BaseConstant.FAIL,"删除失败！");
        }
        jsonObject.put("returnInfo",returnInfo);
        return jsonObject;
    }



    public Double reslutValue(List<Product> allList, Date startTime, Date endTime, String type){
        List<Product> currentList=new ArrayList<Product>();
        if(allList!=null && allList.size()>0){
            for (Product product:allList){
                if(product.getTime()!=null && product.getTime().getTime()>=startTime.getTime()  && product.getTime().getTime()<endTime.getTime()){
                    currentList.add(product);
                }
            }
        }
        Double r=0.0;
        int num=0;
        int t=0;
        if(currentList!=null && currentList.size()>0){
            for (Product product:currentList) {
                if("AQI".equalsIgnoreCase(type)){
                    if(StringUtil.isNotEmpty(product.getAqi())) {
                        int aqi = Integer.parseInt(product.getAqi());
                        num++;
                        r=r+aqi;
                    }
                }else if("PM2".equalsIgnoreCase(type)){
                    if(StringUtil.isNotEmpty(product.getPm2())) {
                        int pm2 = Integer.parseInt(product.getPm2());
                        num++;
                        r=r+pm2;
                    }
                }else if("PM1".equalsIgnoreCase(type)){
                    //PM1
                    if(StringUtil.isNotEmpty(product.getPm1())) {
                        int pm1 = Integer.parseInt(product.getPm1());
                        num++;
                        r=r+pm1;
                    }
                }else if("PM10".equalsIgnoreCase(type)){
                    //PM10
                    if(StringUtil.isNotEmpty(product.getPm10())){
                        int pm10=Integer.parseInt(product.getPm10());
                        num++;
                        r=r+pm10;
                    }
                }else if("HCHO".equalsIgnoreCase(type)){
                    //hcho
                    if(StringUtil.isNotEmpty(product.getHcho())){
                        Double hcho=Double.parseDouble(product.getHcho());
                        num++;
                        r=r+hcho;
                        t=1;
                    }
                }else if("O2".equalsIgnoreCase(type)){
                    //o2
                    if(StringUtil.isNotEmpty(product.getO2())){
                        Double o2=Double.parseDouble(product.getO2());
                        num++;
                        r=r+o2;
                        t=1;
                    }
                }else if("CO2".equalsIgnoreCase(type)){
                    //co2
                    if(StringUtil.isNotEmpty(product.getCo2())){
                        int co2=Integer.parseInt(product.getCo2());
                        num++;
                        r=r+co2;
                    }
                }else if("temp".equalsIgnoreCase(type)){
                    //temp
                    if(StringUtil.isNotEmpty(product.getTemr())){
                        int temr=Integer.parseInt(product.getTemr());
                        num++;
                        r=r+temr;
                    }
                }else if("HIM".equalsIgnoreCase(type)){
                    //hum
                    if(StringUtil.isNotEmpty(product.getHim())){
                        int him=Integer.parseInt(product.getHim());
                        num++;
                        r=r+him;
                    }
                }else if("voc".equalsIgnoreCase(type)){
                    //voc
                    if(StringUtil.isNotEmpty(product.getVoc())){
                        Double voc=Double.parseDouble(product.getVoc());
                        num++;
                        r=r+voc;
                        t=1;
                    }
                }
            }
        }

        if(num>0){
            r=r/num;
            if(t>0){
                r = (double)Math.round(r*100)/100;
            }else{
                r= (double)Math.round(r);
            }
        }
        return r;
    }

    /**
     * 通用验证
     * */
    protected  boolean check(String openid, String state){
        if(StringUtil.isNotEmpty(openid)){
            Member member=memberService.selectByPrimaryKey(openid);
            if(member!=null){
                return true;
            }
        }
        checkModelAndView=new ModelAndView("redirect:"+ ProProperties.getInstance().getWxOauthURL(state));
        return false;
    }

    public Product setTip(Product product){
        if(product!=null){
            //AQI
            if(StringUtil.isNotEmpty(product.getAqi())){
                int aqi=Integer.parseInt(product.getAqi());
                if(aqi>=0 && aqi<80){
                    product.setAqiTip("优秀");
                    product.setAqiColor("#6BCD07");
                }else if(aqi>=80 && aqi<150){
                    product.setAqiTip("良好");
                    product.setAqiColor("#FBD029");
                }else if(aqi>=150 && aqi<200){
                    product.setAqiTip("轻度污染");
                    product.setAqiColor("#FE8800");
                }else if(aqi>=200 && aqi<300){
                    product.setAqiTip("重度污染");
                    product.setAqiColor("#970454");
                }else if(aqi>=300){
                    product.setAqiTip("严重污染");
                    product.setAqiColor("#62001E");
                }
            }
            //PM2.5
            if(StringUtil.isNotEmpty(product.getPm2())){
                int pm2=Integer.parseInt(product.getPm2());
                if(pm2>=0 && pm2<35){
                    product.setPm2Tip("优");
                    product.setPm2Color("#6BCD07");
                }else if(pm2>=35 && pm2<75){
                    product.setPm2Tip("良");
                    product.setPm2Color("#F9F93A");
                }else if(pm2>=75 && pm2<115){
                    product.setPm2Tip("轻度污染");
                    product.setPm2Color("#F18741");
                }else if(pm2>=115 && pm2<150){
                    product.setPm2Tip("中度污染");
                    product.setPm2Color("#F93A3A");
                }else if(pm2>=150 && pm2<250){
                    product.setPm2Tip("重度污染");
                    product.setPm2Color("#C255DD");
                }else if(pm2>=250){
                    product.setPm2Tip("严重污染");
                    product.setPm2Color("#B32BD5");
                }
            }
            //PM1
            if(StringUtil.isNotEmpty(product.getPm1())){
                int pm1=Integer.parseInt(product.getPm1());
                if(pm1>=0 && pm1<35){
                    product.setPm1Tip("优");
                    product.setPm1Color("#6BCD07");
                }else if(pm1>=35 && pm1<75){
                    product.setPm1Tip("良");
                    product.setPm1Color("#F9F93A");
                }else if(pm1>=75 && pm1<115){
                    product.setPm1Tip("轻度污染");
                    product.setPm1Color("#F18741");
                }else if(pm1>=115 && pm1<150){
                    product.setPm1Tip("中度污染");
                    product.setPm1Color("#F93A3A");
                }else if(pm1>=150 && pm1<250){
                    product.setPm1Tip("重度污染");
                    product.setPm1Color("#C255DD");
                }else if(pm1>=250){
                    product.setPm1Tip("严重污染");
                    product.setPm1Color("#B32BD5");
                }
            }
            //PM10
            if(StringUtil.isNotEmpty(product.getPm10())){
                int pm10=Integer.parseInt(product.getPm10());
                if(pm10>=0 && pm10<35){
                    product.setPm10Tip("优");
                    product.setPm10Color("#6BCD07");
                }else if(pm10>=35 && pm10<75){
                    product.setPm10Tip("良");
                    product.setPm10Color("#F9F93A");
                }else if(pm10>=75 && pm10<115){
                    product.setPm10Tip("轻度污染");
                    product.setPm10Color("#F18741");
                }else if(pm10>=115 && pm10<150){
                    product.setPm10Tip("中度污染");
                    product.setPm10Color("#F93A3A");
                }else if(pm10>=150 && pm10<250){
                    product.setPm10Tip("重度污染");
                    product.setPm10Color("#C255DD");
                }else if(pm10>=250){
                    product.setPm10Tip("严重污染");
                    product.setPm10Color("#B32BD5");
                }
            }
            //hcho
            if(StringUtil.isNotEmpty(product.getHcho())){
                Double hcho=Double.parseDouble(product.getHcho());
                if(hcho>=0 && hcho<0.02){
                    product.setHchoTip("优秀");
                    product.setHchoColor("#6BCD07");
                }else if(hcho>=0.02 && hcho<0.05){
                    product.setHchoTip("良好");
                    product.setHchoColor("#F9F93A");
                }else if(hcho>=0.05 && hcho<0.08){
                    product.setHchoTip("轻度污染");
                    product.setHchoColor("#F18741");
                }else if(hcho>=0.08 && hcho<0.15){
                    product.setHchoTip("中度污染");
                    product.setHchoColor("#F93A3A");
                }else if(hcho>=0.15 && hcho<0.3){
                    product.setHchoTip("重度污染");
                    product.setHchoColor("#C255DD");
                }else if(hcho>=0.3){
                    product.setHchoTip("严重污染");
                    product.setHchoColor("#B32BD5");
                }
            }

            //o2
            if(StringUtil.isNotEmpty(product.getO2())){
                Double o2=Double.parseDouble(product.getO2());
                if(o2>=0 && o2<18){
                    product.setO2Tip("空气缺氧");
                    product.setO2Color("#C255DD");
                }else if(o2>=18 && o2<19){
                    product.setO2Tip("轻度浑浊");
                    product.setO2Color("#F9F93A");
                }else if(o2>=19){
                    product.setO2Tip("空气清新");
                    product.setO2Color("#6BCD07");
                }
            }
            //co2
            if(StringUtil.isNotEmpty(product.getCo2())){
                int co2=Integer.parseInt(product.getCo2());
                if(co2>=0 && co2<1000){
                    product.setCo2Tip("空气清新");
                    product.setCo2Color("#6BCD07");
                }else if(co2>=1000 && co2<2000){
                    product.setCo2Tip("轻度浑浊");
                    product.setCo2Color("#F9F93A");
                }else if(co2>=2000 && co2<5000){
                    product.setCo2Tip("空气浑浊");
                    product.setCo2Color("#F93A3A");
                }else if(co2>=5000){
                    product.setCo2Tip("空气缺氧");
                    product.setCo2Color("#C255DD");
                }
            }

            //temp
            if(StringUtil.isNotEmpty(product.getTemr())){
                int temr=Integer.parseInt(product.getTemr());
                 if(temr<6){
                    product.setTemrTip("寒冷");
                    product.setTemrColor("#B32BD5");
                }else if(temr>=6 && temr<11){
                    product.setTemrTip("冷");
                    product.setTemrColor("#C255DD");

                }else if(temr>=11 && temr<15){
                    product.setTemrTip("偏冷");
                    product.setTemrColor("#F18741");

                }else if(temr>=15 && temr<18){
                    product.setTemrTip("凉");
                    product.setTemrColor("#F9F93A");
                }else if(temr>=18 && temr<28){
                    product.setTemrTip("舒适");
                    product.setTemrColor("#6BCD07");
                }else if(temr>=28){
                    product.setTemrTip("炎热");
                    product.setTemrColor("#F93A3A");
                }
            }
            //hum
            if(StringUtil.isNotEmpty(product.getHim())){
                int him=Integer.parseInt(product.getHim());
                if(him>=0 && him<40){
                    product.setHimTip("干燥");
                    product.setHimColor("#F93A3A");

                }else if(him>=40 && him<70){
                    product.setHimTip("舒适");
                    product.setHimColor("#6BCD07");
                }else if(him>=70){
                    product.setHimTip("潮湿");
                    product.setHimColor("#C255DD");
                }
            }
            //voc
            if(StringUtil.isNotEmpty(product.getVoc())){
                Double voc=Double.parseDouble(product.getVoc());
                if(voc>=0 && voc<0.08){
                    product.setVocTip("优秀");
                    product.setVocColor("#6BCD07");
                }else if(voc>=0.08 && voc<0.15){
                    product.setVocTip("良好");
                    product.setVocColor("#F9F93A");
                }else if(voc>=0.15 && voc<0.3){
                    product.setVocTip("轻度污染");
                    product.setVocColor("#F18741");
                }else if(voc>=0.3 && voc<0.5){
                    product.setVocTip("中度污染");
                    product.setVocColor("#F93A3A");
                }else if(voc>=0.5 && voc<0.8){
                    product.setVocTip("重度污染");
                    product.setVocColor("#C255DD");
                }else if(voc>=0.8){
                    product.setVocTip("严重污染");
                    product.setVocColor("#B32BD5");
                }
            }
        }
        return product;
    }



    /**
     * 通用分享可设置标题等
     * */
    protected JSTicketShareResponse Share(HttpServletRequest request, String fxTitle, String fxImgUrl, String fxDesc, String fxUrl, String wxId){
        WxAccountInfo wxAccountInfo= WxMemoryCacheClient.getSingleWxAccountInfo(wxId);
        String url= wxAccountInfo.getBaseURL()+request.getServletPath();
        //设置js分享
        JSTicketShareResponse jsTicketShareResponse = WxApiClient.getJSTicketShareResponse(url,wxId);
        jsTicketShareResponse.setFxTitle(fxTitle);
        jsTicketShareResponse.setFxImgUrl(fxImgUrl);
        jsTicketShareResponse.setFxDesc(fxDesc);
        jsTicketShareResponse.setFxUrl(fxUrl);
        jsTicketShareResponse.setAppid(wxAccountInfo.getAppid());
        return jsTicketShareResponse;
    }

    /**
     * 通用分享可设置
     * */
    protected JSTicketShareResponse Share(HttpServletRequest request,String wxId){
        WxAccountInfo wxAccountInfo= WxMemoryCacheClient.getSingleWxAccountInfo(wxId);
        String url= wxAccountInfo.getBaseURL()+request.getServletPath();
        String c=request.getQueryString();
        if(StringUtil.isNotEmpty(c)){
            url=url+"?"+c;
        }
        //设置js分享
        JSTicketShareResponse jsTicketShareResponse = WxApiClient.getJSTicketShareResponse(url,wxId);
        //jsTicketShareResponse.setFxTitle(ProProperties.getInstance().getfxTitle());
        jsTicketShareResponse.setFxTitle("广汽丰田工会“书伴人生”之跨次元电台");
        jsTicketShareResponse.setFxImgUrl(ProProperties.getInstance().getfxImgUrl());
        //jsTicketShareResponse.setFxDesc(ProProperties.getInstance().getfxDesc());
        jsTicketShareResponse.setFxDesc("将文字阅读的启发和感受，跨越次元，制作成属于自己的广播之声！");
        jsTicketShareResponse.setFxUrl(wxAccountInfo.getBaseURL()+ ProProperties.getInstance().getWxOauthURL(BaseConstant.WX_STATE_ONE));
        jsTicketShareResponse.setAppid(wxAccountInfo.getAppid());
        return jsTicketShareResponse;
    }
}
